/*
 * @Description: 
 * @Author: fhw
 * @Date: 2022-11-28 11:38:16
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, UseFilters, UseGuards } from '@nestjs/common';
import { ApiResponse, ApiOperation, ApiTags, ApiBody, ApiQuery, ApiBearerAuth } from '@nestjs/swagger';
import { ChatUserService } from 'src/chat_user/chat_user.service';
import { HttpExceptionFilter } from 'src/http-exception.filter';
import { CreateUserResumeDto } from './dto/index.dto';
import { UpdateUserImageDto, UpdateUserResumeDto } from './dto/resume.dto';
import { UpdateResumeEducationDto } from './dto/resumeEducation.dto';
import { UpdateExperienceDto } from './dto/resumeExperience.dto';
import { UpdateResumeProjectDto } from './dto/resumeProject.dto';
import { UpdateResumeSkillDto } from './dto/resumeSkill.dto';
import { UpdateResumeSkilltxtDto } from './dto/resumeSkilltxt.dto';
import { ResumeService } from './resume.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('resume')
@ApiTags('简历')
@ApiBearerAuth() // swagger文档设置token
export class ResumeController {
  constructor(
    private readonly resumeService: ResumeService,
    // 聊天用户
    private readonly chatUserService: ChatUserService,
  ) { }

  @Get('/getResumeInfo/:userId')
  @ApiResponse({
    status: 200,
    description: '获取简历详情',
    type: String,
  })
  @ApiOperation({ summary: '获取简历详情', operationId: 'getResumeInfo' })
  async getResumeInfo(@Param('userId') userId: string) {
    return await this.resumeService.getResumeInfo({ userId: Number(userId) })
  }

  // @HttpCode(200)
  // @Post('/createResume')
  // @ApiQuery({
  //   description: '创建简历',
  //   type: CreateUserResumeDto,
  // })
  // @ApiBody({
  //   description: '创建简历',
  //   type: CreateUserResumeDto,
  // })
  // @ApiOperation({ summary: '创建简历', operationId: 'createResume' })
  // @UseFilters(new HttpExceptionFilter())
  // @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  // async createResume(@Body() body: CreateUserResumeDto) {
  //   const { userId } = body
  //   const { data: chatUser } = await this.chatUserService.getUserInfo({ id: userId })
  //   return await this.resumeService.createResume(body, { chatUser })
  // }

  @HttpCode(200)
  @Post('/updateUserResume')
  @ApiQuery({
    description: '更新用户简历信息',
    type: UpdateUserResumeDto,
  })
  @ApiBody({
    description: '更新用户简历信息',
    type: UpdateUserResumeDto,
  })
  @ApiOperation({ summary: '更新用户简历信息', operationId: 'updateUserResume' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateUserResume(@Body() body: UpdateUserResumeDto) {
    const { userId } = body
    const chatUser = await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateUserResume(body, { chatUser })
  }

  @HttpCode(200)
  @Post('/updateUserImage')
  @ApiQuery({
    description: '更新简历头像',
    type: UpdateUserImageDto,
  })
  @ApiBody({
    description: '更新简历头像',
    type: UpdateUserImageDto,
  })
  @ApiOperation({ summary: '更新简历头像', operationId: 'updateUserImage' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateUserImage(@Body() body: UpdateUserImageDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateUserImage(body)
  }

  @HttpCode(200)
  @Post('/updateSkill')
  @ApiQuery({
    description: '更新技能掌握程度',
    type: UpdateResumeSkillDto,
  })
  @ApiBody({
    description: '更新技能掌握程度',
    type: UpdateResumeSkillDto,
  })
  @ApiOperation({ summary: '更新技能掌握程度', operationId: 'updateSkill' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateSkill(@Body() body: UpdateResumeSkillDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateSkill(body)
  }

  @HttpCode(200)
  @Post('/updateSkillText')
  @ApiQuery({
    description: '更新技术描述',
    type: UpdateResumeSkilltxtDto,
  })
  @ApiBody({
    description: '更新技术描述',
    type: UpdateResumeSkilltxtDto,
  })
  @ApiOperation({ summary: '更新技术描述', operationId: 'updateSkillText' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateSkillText(@Body() body: UpdateResumeSkilltxtDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateSkillText(body)
  }

  @HttpCode(200)
  @Post('/updateExperience')
  @ApiQuery({
    description: '更新工作经验成功',
    type: UpdateExperienceDto,
  })
  @ApiBody({
    description: '更新工作经验',
    type: UpdateExperienceDto,
  })
  @ApiOperation({ summary: '更新工作经验', operationId: 'updateExperience' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateExperience(@Body() body: UpdateExperienceDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateExperience(body)
  }

  @HttpCode(200)
  @Post('/updateProject')
  @ApiQuery({
    description: '更新项目',
    type: UpdateResumeProjectDto,
  })
  @ApiBody({
    description: '更新项目',
    type: UpdateResumeProjectDto,
  })
  @ApiOperation({ summary: '更新项目', operationId: 'updateProject' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateProject(@Body() body: UpdateResumeProjectDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateProject(body)
  }

  @HttpCode(200)
  @Post('/updateEducation')
  @ApiQuery({
    description: '更新教育经历',
    type: UpdateResumeEducationDto,
  })
  @ApiBody({
    description: '更新教育经历',
    type: UpdateResumeEducationDto,
  })
  @ApiOperation({ summary: '更新教育经历', operationId: 'updateEducation' })
  @UseFilters(new HttpExceptionFilter())
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateEducation(@Body() body: UpdateResumeEducationDto) {
    const { userId } = body
    await this.chatUserService.getUserInfo({ id: userId })
    return await this.resumeService.updateEducation(body)
  }
}
